cmake_minimum_required(VERSION 3.8)
project(mymangosd)

if (${RELEASE})
  set(CMAKE_BUILD_TYPE "Release")
  message("release mode")
else()
  set(CMAKE_BUILD_TYPE "Debug")
  message("debug mode")
endif()

set(CMAKE_CXX_FLAGS_RELEASE "-Wall -g -std=c++17 -DNDEBUG -DDT_VIRTUAL_QUERYFILTER")
if (${ASAN})
  set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=c++17 -DMYDEBUG -DDT_VIRTUAL_QUERYFILTER -fsanitize=address -fno-omit-frame-pointer")
else()
  set(CMAKE_CXX_FLAGS_DEBUG "-Wall -g -std=c++17 -DMYDEBUG -DDT_VIRTUAL_QUERYFILTER")
endif()

include_directories(
  AFTER
  ../../third_party/a8
  ../../third_party/f8
  /usr/include/glm
  ../../third_party/behaviac/inc
  ../../third_party/recastnavigation/Recast/Include
  ../../third_party/recastnavigation/Detour/Include
  ../../third_party/recastnavigation/DetourTileCache/Include
  behaviac_generated/types
  behaviac_generated/types/internal
  .
)

link_directories(
  /usr/lib64/mysql
  /usr/local/lib
)

aux_source_directory(../../third_party/recastnavigation/Recast/Source
  SRC_LIST
)

aux_source_directory(../../third_party/recastnavigation/Detour/Source
  SRC_LIST
)

aux_source_directory(../../third_party/recastnavigation/DetourTileCache/Source
  SRC_LIST
)

aux_source_directory(.
  SRC_LIST
)

file(GLOB SRC_GRP_LISTENER listener/*.cc listener/*.h)
source_group("listener" FILES ${SRC_GRP_LISTENER})


set(EXECUTABLE_OUTPUT_PATH
  ${PROJECT_BINARY_DIR}/../../bin/mymangosd/bin
)

add_executable(
  mymangosd
  ${SRC_LIST}
  ${SRC_GRP_LISTENER}
)

target_link_libraries(
  mymangosd
  f8
  a8
  pthread
  mysqlclient
  protobuf
  rt
  dl
  util
  crypto
  ssl
  jsoncpp
  curl
  tinyxml2
  backtrace
  )

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
  target_link_libraries(
    mymangosd
    #behaviac_gcc_release
    boost_stacktrace_backtrace
    boost_stacktrace_addr2line
    )
else()
  target_link_libraries(
    mymangosd
    tcmalloc
    #behaviac_gcc_release
    )
endif()

ADD_SUBDIRECTORY(../../third_party/a8/a8 a8)
ADD_SUBDIRECTORY(../../third_party/f8/f8 f8)
